package cn.kgc.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/*SHA SHA256 MD5*/
public class MD5Utils {
    public static String encodeStr(String oldString){
        try {
            MessageDigest md5=MessageDigest.getInstance("md5");
            //-128 127
            byte[] bs=md5.digest(oldString.getBytes());
            StringBuilder sb=new StringBuilder();
            System.out.println("打散后的"+new String(bs));
            int temp=0;
            for (byte b:bs){
                temp=b;
                if (temp<0){
                    temp*=-2;
                }
                sb.append(Integer.toHexString(temp));
            }
            System.out.println("加密后:"+sb.toString());
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
}
